package com.itheima.springboottlias.annotation;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author iTaotao
 * @date 2023/7/19 14:23
 * @desciption: 删除切点
 */
@Slf4j
@Component
//@Aspect
public class MyAspect3 {
    @Pointcut("@annotation(com.itheima.springboottlias.annotation.SysLog)")
    public void pt() {

    }

    @Before("pt()")
    public void before(JoinPoint joinPoint) {
        log.info("before ...");

    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable{
//        1.获取目标类名
        String name = joinPoint.getTarget().getClass().getName();
        log.info("获取目标类名: {}",name);
//        2.目标方法名
        String methodName = joinPoint.getSignature().getName();
        log.info("目标方法名: {}",methodName);

//        3.获取方法执行时所需要的参数
        Object[] args = joinPoint.getArgs();
        log.info("获取方法执行时所需要的参数: {}", Arrays.toString(args));
//        4.原来方法的返回值
        Object proceed = joinPoint.proceed();
        log.info("原来方法的返回值: {}", proceed);
        return proceed;


    }

}
